public with sharing class TestTriggers {
	private static Account testAcc;
	private static Opportunity testOpp;
	private static Contact testCon;
	private static OpportunityContactRole testConRole;
	private static Date todayDate = Date.today();
	private static Campaign camp;
	private static CampaignMember cm;
		
	static TestMethod void testTriggerTasks2()
	{
		List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Opportunity' and isActive=true];
		Map<String,String> opportunityRecordTypes = new Map<String,String>{};
		for(RecordType rt: rtypes)
		opportunityRecordTypes.put(rt.Name,rt.Id);
    	List<RecordType> crtypes = [Select Name, Id From RecordType where sObjectType='Campaign' and isActive=true];
		Map<String, ID> campaignRecordTypes = new Map<String, ID>{};
		for(RecordType crt: crtypes)
			campaignRecordTypes.put(crt.Name, crt.ID);
		testAcc=new Account(name='testAccount');
		insert testAcc;
		testCon=new Contact(lastname='testCon', AccountId=testAcc.id);
		insert testCon;
		Contact testCon2=new Contact(lastname='testCon2', AccountId=testAcc.id);
		insert testCon2;
		
		Test.startTest();
		testOpp=new Opportunity(name='testOpp', AccountId=testAcc.id, StageName='Invoiced', CloseDate=todayDate, RecordTypeId=opportunityRecordTypes.get('Subscriptions'));
		insert testOpp;
		Opportunity testOpp2=new Opportunity(name='testOpp', AccountId=testAcc.id, StageName='Invoiced', CloseDate=todayDate, RecordTypeId=opportunityRecordTypes.get('Donations & Purchases'));
		insert testOpp2;
		testConRole=new OpportunityContactRole(ContactId=testCon.id, OpportunityId=testOpp.id, Role='Purchaser', IsPrimary=False);
		insert testConRole;
		update testOpp;
		testConRole=new OpportunityContactRole(ContactId=testCon.id, OpportunityId=testOpp.id, Role='Purchaser', IsPrimary=True);
		insert testConRole;
		update testOpp;
		Test.stopTest();
	}
	static TestMethod void testTriggerTasks()
	{	
		/* Test For CampaignMember.trigger */
		/*
		Account account = new Account(Name = 'Test Account');
		insert account;
		Contact contact = new Contact(FirstName = 'Test', LastName = 'Contact', AccountId = account.Id);
		insert contact;
		Campaign campaign = new Campaign();
		campaign.Name = 'Test Campaign';
		campaign.RecordTypeId = [SELECT Id FROM RecordType WHERE Name='SAKGF Training' AND SobjectType='Campaign'][0].Id;
		insert campaign;
		CampaignMemberStatus campaignMemberStatus1 = new CampaignMemberStatus(CampaignId = campaign.Id, HasResponded = false, Label = 'Booked', SortOrder = 3);
		insert campaignMemberStatus1;
		CampaignMemberStatus campaignMemberStatus2 = new CampaignMemberStatus(CampaignId = campaign.id, HasResponded = false, Label = 'Attended', SortOrder = 4);
		insert campaignMemberStatus2;
		Opportunity opportunity = new Opportunity();
		opportunity.Name = 'Test Opportunity';
		opportunity.AccountId = account.Id;
		opportunity.CloseDate = System.Now().Date();
		opportunity.StageName = 'To Invoice';
		insert opportunity;
		Product2 product2 = new Product2(Name = 'Test Product', isActive = true);
		insert product2;
		Id StandardPriceBookId = [SELECT Id FROM Pricebook2 WHERE IsStandard = TRUE LIMIT 1][0].Id;
		PricebookEntry pricebookEntry = new PricebookEntry(UnitPrice = 10, Pricebook2Id = StandardPriceBookId, IsActive = true, Product2Id = product2.Id);
		insert pricebookEntry;
		Test.startTest();
		CampaignMember campaignMember = new CampaignMember();
		campaignMember.ContactId = contact.Id;
		campaignMember.CampaignId = campaign.Id;
		campaignMember.Status = 'Booked';
		campaignMember.Website_Fee__c = 1.00;
		//insert campaignMember;
		OpportunityLineItem opportunityLineItem = new OpportunityLineItem();
		opportunityLineItem.Quantity = 1;
		opportunityLineItem.PricebookEntryId = pricebookEntry.id;
		opportunityLineItem.Campaign__c = campaign.Id;
		opportunityLineItem.OpportunityId = opportunity.Id;
		opportunityLineItem.Contact__c = contact.Id;
		opportunityLineItem.TotalPrice = 20;
		opportunityLineItem.Campaign_Member_ID__c = campaignMember.Id;
		//insert opportunityLineItem;
		campaignMember.Income_Item__c = opportunity.Id;
		//update campaignMember;
		opportunityLineItem.Member_Status__c = 'Declined';
		//update opportunityLineItem;
		//update campaignMember;
		Test.stopTest();
		*/
	}
	
	static TestMethod void testTriggerTasks3()
	{	////Lead create and convert
		testAcc=new Account(name='testAccount');
		insert testAcc;
		Contact testCon2=new Contact(lastname='testCon2', AccountId=testAcc.id);
		insert testCon2;
		testCon=new Contact(lastname='testCon', AccountId=testAcc.id);
		insert testCon;
		List<RecordType> crtypes = [Select Name, Id From RecordType where sObjectType='Campaign' and isActive=true];
		Map<String, ID> campaignRecordTypes = new Map<String, ID>{};
		for(RecordType crt: crtypes)
			campaignRecordTypes.put(crt.Name, crt.ID);
		testOpp=new Opportunity(name='testOpp', AccountId=testAcc.id, StageName='Invoiced', CloseDate=todayDate);
		insert testOpp;
		Lead lead = new Lead(LastName='testLead', Enquiry_Type__c='Expression of Interest', Company='test', Status='Open');
		insert lead;
		Database.LeadConvert lc = new database.LeadConvert();
		lc.setLeadId(lead.id); 
		LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
		lc.setConvertedStatus(convertStatus.MasterLabel);
		Database.LeadConvertResult lcr = Database.convertLead(lc);
		System.assert(lcr.isSuccess());
		camp=new Campaign(name='test', Has_Workshops__c='Yes', Publish_To__c='Program Schools', Job_Code__c='423 VET', Budget_Allocated__c=1, RecordTypeId=campaignRecordTypes.get('SAKGF Training'));
		insert camp;
		CampaignMemberStatus cms=new CampaignMemberStatus(CampaignId=camp.id, HasResponded=true, Label='Accepted', SortOrder=3);
		insert cms;
		CampaignMemberStatus cms1=new CampaignMemberStatus(CampaignId=camp.id, HasResponded=False, Label='Declined', SortOrder=4);
		insert cms1;
		Test.startTest();
		cm=new CampaignMember(ContactId=testCon.id, Website_Fee__c=3,Income_Item__c=testOpp.id, CampaignId=camp.id, Status='Accepted');
		insert cm;
		CampaignMember cm2=new CampaignMember(ContactId=testCon2.id, Website_Fee__c=3,CampaignId=camp.id, Status='Booked', Type__c = 'Promo');
		insert cm2;
		cm.Article_Published_Where__c='test';
		update cm;
		cm.Status='Declined';
		update cm;
		List<Pricebook2> pb = [select name, isactive from Pricebook2 where IsStandard = true limit 1];
		Product2 product=new Product2(name='test', isActive=true);
		insert product;
		PricebookEntry pE= new PricebookEntry(UnitPrice=10, Pricebook2Id=pb[0].id, isActive=true, Product2Id=product.id);
		insert pE;
		Validation.setOppTriggerNotFired();
		OpportunityLineItem oLI=new OpportunityLineItem(Quantity=1, PricebookEntryId=pE.id, Campaign__c=camp.Id, OpportunityId=testOpp.id, Contact__c=testCon2.id, TotalPrice=20);
		insert oLI;
		Test.stopTest();
	}
}